#include "mserver.h"

#include <QTcpSocket>

mServer::mServer(QObject *parent) :
    QTcpServer(parent)
{
    totalClient = 0;
    this->listen(QHostAddress::Any,6666);
}

void mServer::incomingConnection(int socketDescriptor)
{

    if(totalClient>=200)
    {
        QTcpSocket* temp = new QTcpSocket();
        temp->setSocketDescriptor(socketDescriptor);
        QString send = "NOO";
        temp->write(send.toLatin1());
        qDebug()<<"Print is working!";
        delete temp;
    }
    else
    {
        thread = new ServerThread(this,socketDescriptor);
        QObject::connect(thread,SIGNAL(out()),this,SLOT(outConnect()));
        thread->start();
        totalClient++;
        qDebug()<<"hello!---socket:"<<socketDescriptor;
    }
}
void mServer::outConnect()
{
    totalClient--;
    qDebug()<<"disconnect!!!";
    delete thread;
}
